string IM = "This is my new way to annyoy people with my pour spelling and puncuation mistakes"; 

// change the IM above  1183 limmit





integer loading = FALSE;
string first_name = "";
string last_name = "";
key avi_key = NULL_KEY;
integer notecard_index = 0;
integer total_line = 0;
integer loading_index = 0;
list loading_list = ["-","\\","|","/"];
//=================================================
key gSetupQueryId;
integer gSetupNotecardLine;
integer gLine_number = 0;
string gSetupNotecardName = "";
// ======================================================
default
{
    state_entry()
    {
        llOwnerSay("touch prim to send ...");
        gSetupNotecardName = llGetInventoryName(INVENTORY_NOTECARD,0);
    }
    touch_start(integer int)
    {
        if ( (llDetectedKey(0) == llGetOwner()) && (!loading) )
        {
            llOwnerSay("  loading, please wait ...");    
            loading = TRUE;
            gSetupNotecardLine = 0;
            gSetupQueryId = llGetNumberOfNotecardLines(gSetupNotecardName);                         
        }
    }
    changed(integer change)
    {
        if (change & CHANGED_INVENTORY)
            llOwnerSay("touch prim to send ...");
    }
    dataserver(key queryId, string data)
    {
        if(queryId == gSetupQueryId) 
        {
            if(data != EOF)
            {
                string line = llStringTrim(data,STRING_TRIM);
                        
                if ( (line != "") && (line != "1") && (llGetSubString(line,0,1) != "//") && (gSetupNotecardLine != 0) )
                {                
                    notecard_index += 1; 
                    if (notecard_index > 3)
                        notecard_index = 1;
                        
                    if (notecard_index == 1)
                        first_name = line;
                    else if (notecard_index == 2)
                        last_name = line;
                    else if (notecard_index == 3)
                        avi_key = (key)line;
                 
                    if (notecard_index == 3)
                    {
                        llInstantMessage(avi_key,IM);
                        llOwnerSay("  IM sent to "+first_name+" "+last_name+".");
                        llGiveInventory(avi_key,llGetInventoryName(INVENTORY_OBJECT, 0));
                       // llGiveInventory(avi_key,llGetInventoryName(INVENTORY_NOTECARD, 0));
                        
                    }
                    
                      
                }
                                                        
                if (gSetupNotecardLine == 0)
                    total_line = (integer)data;                                                                       
                llSetText("Loading [ "+gSetupNotecardName+" ] "+llGetSubString((string)((float)gSetupNotecardLine / (float)total_line * 100.0),0,1)+"%\nPlease wait "+llList2String(loading_list,loading_index)+" ...",<1.0,1.0,1.0>,1.0);    
    
                loading_index = loading_index + 1;
                if (loading_index > 3)
                    loading_index = 0;
                gSetupQueryId = llGetNotecardLine(gSetupNotecardName,++gSetupNotecardLine); 
            }
            else
            {
                llOwnerSay("  loading completed.");
                llSetText(" ",<0.0,0.0,0.0>,0.0);
                loading = FALSE;
            }
        }
    }        
}
